package it.interceptor;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import it.service.ipml.ConstantIpml;
import it.service.ipml.StudentServiceIpml;

public class RegistInterceptor implements HandlerInterceptor {

	@Autowired
	private ConstantIpml constantIpml;

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// TODO Auto-generated method stub
		String expipeTimeStr = constantIpml.REGIST_EXPIRE_TIME;
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date expipeTime = format.parse(expipeTimeStr);
		Date now = new Date();
		if (now.getTime() > expipeTime.getTime()) {
			request.getRequestDispatcher("/WEB-INF/jsp/expire.jsp").forward(request, response);
			return false;
		}
		return true;
	}

	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub

	}

	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub

	}

}
